package com.dbb.util;

import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.math.RandomUtils;

public class StringUtil {
	public static String[] userNames = {"Admin", "Root", "Viv", "Abe", "Dbb"};
	public static String[] userCnNames = {"A", "B", "C", "Abe", "D"};
	public static String[] phoneNums = {"1352312312", "Root", "Viv"};
	
	public static String getRandomArray(String[] ss) {
		return ss[RandomUtils.nextInt(ss.length)];
	}
	
	public static String getRandomString(int minLength, int maxLength) {
		String s = "";
		do{
			s = RandomStringUtils.randomAlphabetic(RandomUtils.nextInt(maxLength)).toLowerCase();
		}while(s.length() < minLength);
		return s;
	}
	
	public static String getRandomFirstUpperString(int minLength, int maxLength) {
		return getFirstUpperString(getRandomString(minLength, maxLength));
	}
	
	public static String getFirstUpperString(String s) {
		StringBuffer sb = new StringBuffer();
		String[] list = s.split(" ");
		for(String str : list) {
			sb.append(str.substring(0,1).toUpperCase() + str.substring(1) + " ");
		}
		return sb.toString();
	}
	
	public static String getNumString(int count) {
		return RandomStringUtils.randomNumeric(count);
	}
	
	public static Integer getRandomInt(int min, int max) {
		int i = 0;
			do{
				i = RandomUtils.nextInt(max);
			} while(i < min);
		return i;
	}
	
	public static Integer getPower(int count) {
		int base = 10;
		for(int i = 1; i < count; i++) {
			base *= 10;
		}
		return base;
	}
	
	public static String getCellPhoneNum() {
		return "13" + getNumString(9);
	}
	
	public static String getPhoneNum() {
		String s = "";
		do{
			s = getNumString(8);
		} while(s.startsWith("0"));
		return s;
	}
	
	public static Float getRandomFloat(int min, int max, int deci) {
		Integer i = 0;
		do{
			i = RandomUtils.nextInt(max * getPower(deci));
		} while (i < min * getPower(deci));
		
		float f = i.floatValue();
		return f/getPower(deci);
	}
	
	public static void main(String[] args) {
		System.out.println(getFirstUpperString("abcs dfdsf sdsdf"));
		System.out.println(getRandomArray(userNames));
		System.out.println(getRandomString(5, 10));
		System.out.println(getRandomFirstUpperString(5,10));
		System.out.println(getRandomFloat(8, 15, 2));
		System.out.println(getNumString(13));
		System.out.println(getRandomInt(100, 1000));
		System.out.println(Math.log10(100));
		System.out.println(getCellPhoneNum());
		System.out.println(getPhoneNum());
		System.out.println(getNumString(2));
		
	}

	public static String getEmail() {
		// TODO Auto-generated method stub
		return RandomStringUtils.randomAlphanumeric(5) + "@gmail.com";
	}

	public static Long getLongId() {
		return RandomUtils.nextLong();
	}
}
